package de.mroedig.appindiesonne.menu;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import de.mroedig.appindiesonne.R;

public class HauttypWaehlenMenu extends Activity {

	private int hauttyp = 1;
	private SeekBar hauttypBar;
	private TextView hauttypZahl;
	private TextView hauttypBeschreibung;
	private Button weiterButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.hauttypmenue);

		this.weiterButton = (Button) this
				.findViewById(R.id.hauttypWeiterButton);
		this.weiterButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				SharedPreferences mPrefs = HauttypWaehlenMenu.this
						.getSharedPreferences("appInDieSonnePrefs",
								MODE_PRIVATE);
				Editor editor = mPrefs.edit();

				editor.putInt("hauttyp", HauttypWaehlenMenu.this.hauttyp);
				editor.commit();
				Intent intent = new Intent(HauttypWaehlenMenu.this,
						ZoneWaehlen.class);
				HauttypWaehlenMenu.this.startActivity(intent);

			}
		});
		this.hauttypBar = (SeekBar) this.findViewById(R.id.hauttypBar);
		this.hauttypZahl = (TextView) this.findViewById(R.id.hauttypzahl);
		this.hauttypBeschreibung = (TextView) this
				.findViewById(R.id.hauttypbeschreibung);
		this.hauttypBar
				.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

					@Override
					public void onStopTrackingTouch(SeekBar seekBar) {
						this.seekBarListenerStandardMethode();
					}

					@Override
					public void onStartTrackingTouch(SeekBar seekBar) {
						this.seekBarListenerStandardMethode();
					}

					@Override
					public void onProgressChanged(SeekBar seekBar,
							int progress, boolean fromUser) {
						this.seekBarListenerStandardMethode();
					}

					private void seekBarListenerStandardMethode() {
						HauttypWaehlenMenu.this.hauttypZahl
								.setText(HauttypWaehlenMenu.this.hauttypBar
										.getProgress() + 1 + "");
						HauttypWaehlenMenu.this.hauttyp = HauttypWaehlenMenu.this.hauttypBar
								.getProgress() + 1;
						HauttypWaehlenMenu.this
								.setzeBeschreibung(HauttypWaehlenMenu.this.hauttypBar
										.getProgress());
					}
				});
		this.holePrefs();
	}

	private void holePrefs() {
		SharedPreferences mPrefs = this.getSharedPreferences(
				"appInDieSonnePrefs", MODE_PRIVATE);
		this.hauttypBar.setProgress(mPrefs.getInt("hauttyp", 0) - 1);
	}

	private void setzeBeschreibung(int progress) {

		switch (progress) {
		case 0:
			this.hauttypBeschreibung.setText(R.string.hauttyp_1);
			break;
		case 1:
			this.hauttypBeschreibung.setText(R.string.hauttyp_2);
			break;
		case 2:
			this.hauttypBeschreibung.setText(R.string.hauttyp_3);
			break;
		case 3:
			this.hauttypBeschreibung.setText(R.string.hauttyp_4);
			break;
		case 4:
			this.hauttypBeschreibung.setText(R.string.hauttyp_5);
			break;
		case 5:
			this.hauttypBeschreibung.setText(R.string.hauttyp_6);
		}
	}
}
